<template>
    <div>
        <div class="container">
            <div class="admin-index">
                <div>
                    <div class="e-p-b-30" style="font-size: 18px;">库存表</div>
                    <el-radio-group v-model="dataType" class="e-m-b-45">
                        <el-radio-button label="0">数据中台</el-radio-button>
                        <el-radio-button label="1">库存表</el-radio-button>
                        <el-radio-button label="2">线上回收统计</el-radio-button>
                        <el-radio-button label="3">门店回收统计</el-radio-button>
                        <el-radio-button label="4">小哥入库统计</el-radio-button>
                        <el-radio-button label="5">出库销售统计</el-radio-button>
                    </el-radio-group>
                </div>
                <div>
                    <el-form :inline="true" class="demo-form-inline">
                        <el-form-item label="所属加盟商">
                            <franchiseList v-model="listFranchiseId" :firstSelect="true" @change="selectFranchise"></franchiseList>
                        </el-form-item>
                        <el-form-item label="站点筛选">
                            <storeList v-model="listStoreId" @change="selectStore"></storeList>
                        </el-form-item>
                        <el-form-item label="站点员工" v-if="listStoreId > 0 && !loading">
                            <userList v-model="staffId" :selectType="0" :franchiseId="listFranchiseId" :storeId="listStoreId" @change="selectUser"></userList>
                        </el-form-item>
                        <!-- <el-form-item>
                            <el-button @click="downloadwithdrawa()"
                                type="primary" plain><i class="iconfont icon-excel"></i>导出Excel</el-button>
                        </el-form-item> -->
                    </el-form>
                </div>
                <div class="flex">
                    <div class="e-flex-1">
                        <!-- 门店回收统计 -->
                        <statistics-recycle-store ref="statistics" :franchiseId="listFranchiseId" :storeId="listStoreId" :staffId="staffId"></statistics-recycle-store>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import storeList from '@/components/form-select-type/storeList.vue'
import franchiseList from '@/components/form-select-type/franchiseList.vue'
import userList from '@/components/form-select-type/userList.vue'
export default {
    layout: 'admin',
    components: {
        franchiseList,
        userList,
        storeList
    },
    data() {
        return {
            loading: false,
            dataType: 3,
            tableData: [],
            listFranchiseId: null,
            staffId: null,
            listStoreId: null,
            loadingUserData: false
        };
    },
    watch: {
        dataType(val) {
            console.log(val)
            let type = Number(val)
            switch (type) {
                case 0:
                    this.$router.push({
                        path: '/'
                    })
                    break;
                case 1:
                    this.$router.push({
                        path: '/statistics/inventory'
                    })
                    break;
                case 2:
                    this.$router.push({
                        path: '/statistics/online'
                    })
                    break;
                case 3:
                    this.$router.push({
                        path: '/statistics/store'
                    })
                    break;
                case 4:
                    this.$router.push({
                        path: '/statistics/onlinestorage'
                    })
                    break;
                case 5:
                    this.$router.push({
                        path: '/statistics/storeSell'
                    })
                    break;
            }
        },
    },
    mounted() {
        // this.getstorelist()
    },
    methods: {
        changeStore() {
            // this.loading = true
            // setTimeout(() => {
            // 	this.loading = false
            // }, 500)
        },
        // 选择站点
        selectStore(value){
            this.loading = true
            this.listStoreId = value
            this.staffId = null
            setTimeout(() => {
            	this.loading = false
                this.$refs.statistics.getList()
            }, 100)
        },
        selectUser(value){
            this.loading = true
            this.staffId = value
            setTimeout(() => {
            	this.loading = false
                this.$refs.statistics.getList()
            }, 100)
        },
        // downloadwithdrawa() {
        //     this.$axios.post('/Statistics/StockOverview/Download', {
                
        //     }, {
        //         responseType: 'blob'
        //     }).then(res => {
        //         console.log(res)
        //         let content = res;
        //         let fileName = '库存表.xls'
        //         this.utils.saveAndExport(content, fileName)
        //     })
        // },
        // 选择加盟商
        selectFranchise(value){
            console.log('选择加盟商',value)
            this.loadingUserData = true
            this.loading = true
            this.listFranchiseId = value
            this.listStoreId = null
            setTimeout(() => {
            	this.loading = false
                this.loadingUserData = false
                this.$refs.statistics.getList()
            }, 100)
        },
        // getstorelist() {
        //     this.$axios.post('/Select/StoreList', {
        //         "pageIndex": 1,
        //         "pageSize": 999,
        //     }).then((res) => {
        //         console.log(res)
        //         this.StoreList = res.rows
        //         // this.StoreList.unshift({
        //         // 	id: "",
        //         // 	name: '全部'
        //         // })
        //     }).catch((err) => {
        //         this.loading = false
        //     })
        // },
    }
};
</script>
<style lang="scss" scoped></style>